package com.ftg.learn.loadbalance;

import java.util.Arrays;
import java.util.List;

/**
 * @author 布衣
 */
public class RandomQuery {

    /**
     * 轮询算法
     * @param list
     * @param index
     * @return
     */
    public RedisInstance get(List<RedisInstance> list, int index) {
        return list.get((int)(Math.random()*list.size()));
    }

    public static void main(String[] args) {

        RandomQuery t = new RandomQuery();
        List<RedisInstance> list = Arrays.asList(new RedisInstance("127.0.0.1",6380),new RedisInstance("127.0.0.1",6381),new RedisInstance("127.0.0.1",6382));
        for (int i = 0; i < 10; i++) {
            System.out.println(t.get(list, i)+"==>ip redis 从服务器");
        }

    }

}
